package com.tibbytang.opengllearn.main

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.tibbytang.opengllearn.R
import com.tibbytang.opengllearn.empty.EmptyActivity
import com.tibbytang.opengllearn.train01.PointsActivity
import com.tibbytang.opengllearn.train02.LinesActivity
import com.tibbytang.opengllearn.train03.LineStripActivity
import com.tibbytang.opengllearn.train04.LineLoopActivity
import com.tibbytang.opengllearn.train05.TriangleActivity
import com.tibbytang.opengllearn.train06.SquareActivity
import com.tibbytang.opengllearn.train07.TextureActivity
import com.tibbytang.opengllearn.train08.TrianglesActivity
import com.tibbytang.opengllearn.train09.TriangleStripActivity
import com.tibbytang.opengllearn.train10.TriangleFanActivity
import kotlinx.android.synthetic.main.activity_main.*
import me.drakeet.multitype.MultiTypeAdapter

class MainActivity : AppCompatActivity(),
    OpenGLItemViewBinder.OnItemClickListener {
    private val list = listOf<String>(
        "环境搭建",
        "绘制Point GL_POINTS",
        "绘制Lines GL_LINES ",
        "绘制Lines GL_LINE_STRIP ",
        "绘制Lines GL_LINE_LOOP",
        "绘制三角形 GL_TRIANGLES ",
        "绘制四边形 GL_TRIANGLE_STRIP ",
        "纹理贴图 "
    )
    private val multiTypeAdapter = MultiTypeAdapter()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        recyclerview.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)
        multiTypeAdapter.register(
            String::class.java,
            OpenGLItemViewBinder(this)
        )
        multiTypeAdapter.items = list
        recyclerview.adapter = multiTypeAdapter
    }

    override fun onItemClick(position: Int) {
        when (position) {
            0 -> startActivity(Intent(this, EmptyActivity::class.java))
            1 -> startActivity(Intent(this, PointsActivity::class.java))
            2 -> startActivity(Intent(this, LinesActivity::class.java))
            3 -> startActivity(Intent(this, LineStripActivity::class.java))
            4 -> startActivity(Intent(this, LineLoopActivity::class.java))
            5 -> startActivity(Intent(this, TriangleActivity::class.java))
            6 -> startActivity(Intent(this, SquareActivity::class.java))
            7 -> startActivity(Intent(this, TextureActivity::class.java))
            8 -> startActivity(Intent(this, TrianglesActivity::class.java))
            9 -> startActivity(Intent(this, LinesActivity::class.java))
            10 -> startActivity(Intent(this, TriangleStripActivity::class.java))
            11 -> startActivity(Intent(this, TriangleFanActivity::class.java))
            else -> return
        }
    }
}
